//
//  UIDevice+Extensions.swift
//  YCCamera
//
//  Created by Billy on 4/11/25.
//

import UIKit

extension UIDevice {
    // 获取设备型号标识符
    var modelIdentifier: String {
        var systemInfo = utsname()
        uname(&systemInfo)
        let machineMirror = Mirror(reflecting: systemInfo.machine)
        let identifier = machineMirror.children.reduce("") { identifier, element in
            guard let value = element.value as? Int8, value != 0 else { return identifier }
            return identifier + String(UnicodeScalar(UInt8(value)))
        }
        return identifier
    }
    
    // 获取设备具体型号名称
    var modelName: String {
        let identifier = modelIdentifier
        
        switch identifier {
        
        // MARK: - iPhone 16 Series
        case "iPhone17,3": return "iPhone 16"
        case "iPhone17,4": return "iPhone 16 Plus"
        case "iPhone17,1": return "iPhone 16 Pro"
        case "iPhone17,2": return "iPhone 16 Pro Max"
        case "iPhone17,5": return "iPhone 16e"
        
        // MARK: - iPhone 15 Series
        case "iPhone15,4": return "iPhone 15"
        case "iPhone15,5": return "iPhone 15 Plus"
        case "iPhone16,1": return "iPhone 15 Pro"
        case "iPhone16,2": return "iPhone 15 Pro Max"
        
        // MARK: - iPhone 14 Series
        case "iPhone14,7": return "iPhone 14"
        case "iPhone14,8": return "iPhone 14 Plus"
        case "iPhone15,2": return "iPhone 14 Pro"
        case "iPhone15,3": return "iPhone 14 Pro Max"
        
        // MARK: - iPhone 13 Series
        case "iPhone14,5": return "iPhone 13"
        case "iPhone14,4": return "iPhone 13 mini"
        case "iPhone14,2": return "iPhone 13 Pro"
        case "iPhone14,3": return "iPhone 13 Pro Max"
        case "iPhone14,6": return "iPhone SE (3rd generation)"
        
        // MARK: - iPhone 12 Series
        case "iPhone13,2": return "iPhone 12"
        case "iPhone13,1": return "iPhone 12 mini"
        case "iPhone13,3": return "iPhone 12 Pro"
        case "iPhone13,4": return "iPhone 12 Pro Max"
        case "iPhone12,8": return "iPhone SE (2nd generation)"
        
        // MARK: - iPad Pro Series
        case "iPad14,3", "iPad14,4": return "iPad Pro 12.9-inch (6th generation)"
        case "iPad14,1", "iPad14,2": return "iPad Pro 11-inch (4th generation)"
        case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11": return "iPad Pro 12.9-inch (5th generation)"
        case "iPad13,4", "iPad13,5", "iPad13,6", "iPad13,7": return "iPad Pro 11-inch (3rd generation)"
        case "iPad8,11", "iPad8,12": return "iPad Pro 12.9-inch (4th generation)"
        case "iPad8,9", "iPad8,10": return "iPad Pro 11-inch (2nd generation)"
        
        // MARK: - iPad Air Series
        case "iPad13,16", "iPad13,17": return "iPad Air (5th generation)"
        case "iPad13,1", "iPad13,2": return "iPad Air (4th generation)"
        
        // MARK: - iPad Series
        case "iPad13,18", "iPad13,19": return "iPad (10th generation)"
        case "iPad12,1", "iPad12,2": return "iPad (9th generation)"
        case "iPad11,6", "iPad11,7": return "iPad (8th generation)"
        
        // MARK: - iPad mini Series
        case "iPad14,5", "iPad14,6": return "iPad mini (6th generation)"
        
        default: return "iPhone"
        }
    }
}

